package com.pro.controller;

import com.pro.pojo.JsBeforeUser;
import com.pro.pojo.JsUser;
import com.pro.pojo.JsUserOrder;
import com.pro.pojo.JsonData;
import com.pro.service.JsUserCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * ClassName:JsUserCourseController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2021/11/11 上午 9:42
 * @Author: WYH
 */
@Controller
@RequestMapping("/course")
public class JsUserCourseController {

    @Autowired
    private JsUserCourseService jsUserCourseService;

    @RequestMapping("/getAllCourse")
    @ResponseBody
    public JsonData getAllCourse(String orderPaymentChannel, String orderSource, String orderStatus) {
        orderPaymentChannel = orderPaymentChannel != null ? "%"+orderPaymentChannel+"%" : "%%";
        orderSource = orderSource != null ? "%"+orderSource+"%" : "%%";
        orderStatus = orderStatus != null ? "%"+orderStatus+"%" : "%%";
        List<JsUserOrder> allCourse = jsUserCourseService.getAllCourse(orderPaymentChannel, orderSource, orderStatus);
        int count = jsUserCourseService.count(orderPaymentChannel, orderSource, orderStatus);
        return allCourse != null ? JsonData.buildSuccess(allCourse,count) : JsonData.buildError("数据格式异常");
    }

    @RequestMapping("/delCourse")
    @ResponseBody
    public JsonData delCourse(Integer orderId) {
        Boolean aBoolean = jsUserCourseService.delCourse(orderId);
        return aBoolean != null ? JsonData.buildSuccess(aBoolean) : JsonData.buildError("数据格式异常");
    }

    @RequestMapping("/getUser")
    @ResponseBody
    public JsonData getUser(Integer orderId) {
        JsBeforeUser user = jsUserCourseService.getUser(orderId);
        return user != null ? JsonData.buildSuccess(user) : JsonData.buildError("数据格式异常");
    }
}
